package com.knowvoyage.knowvoyageserver.controller;

import com.knowvoyage.knowvoyageserver.pojo.dto.LoginDTO;
import com.knowvoyage.knowvoyageserver.pojo.dto.RegisterDTO;
import com.knowvoyage.knowvoyageserver.pojo.vo.Result;
import com.knowvoyage.knowvoyageserver.service.AuthService;
import com.knowvoyage.knowvoyageserver.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "认证类", description = "用于登录注册")
@Slf4j
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {
    private final AuthService authService;
    private final UserService userService;

    @Operation(summary = "用户注册", description = "用户注册接口")
    @PostMapping("/register")
    public Result<String> register(@Validated @RequestBody RegisterDTO registerDTO) {
        log.info("用户注册调用,用户{}",registerDTO.getPhone());
        return authService.register(registerDTO);
    }

    @Operation(summary = "用户登录", description = "用户登录接口")
    @PostMapping("/login")
    public Result<Map<String, Object>> login(@Validated @RequestBody LoginDTO loginDTO) {
        log.info("用户登录调用,用户{}",loginDTO.getPhone());
        return authService.login(loginDTO);
    }
}
